<?php
declare(strict_types=1);

namespace App\Service\Pushapp;
use Exception;
use App\Service\Pushapp\JpushService;
// use App\Service\Xhqapp\HuaweiService;
use App\Service\Pushapp\XiaomiService;
use App\Service\Pushapp\VivosService;
use App\Service\Pushapp\OpposService;
use Hyperf\Di\Annotation\Inject;
/**
 * APP消息推送服务
 */
class MpushService
{

    #[Inject]
    public JpushService $jpushService;
    // public HuaweiService $huaweiService;
    // #[Inject]
    // public XiaomiService $xiaomiService;
    // #[Inject]
    // public VivosService $vivosService;
    // #[Inject]
    // public OpposService $opposService;
    /**
     * [singlePushByUser app单个推送]
     * @param  array  $user    [description]
     * @param  string $title   [description]
     * @param  string $content [description]
     * @param  array  $extra   [description]
     * @return [type]          [description]
     */
    public function singlePushByUser(array $user, string $title, string $content, array $extra)
    {
        if (empty($user)) {
            return false;
        }
        $pushData = [
            'title' => $title,
            'subTitle' => '',
            'content' => $content,
            'extra' => $extra,
            'badge' => '',
            //'uid' => $user['user_id']
        ];
        if ($user['app_type'] == 'ios') {
            $pushData['platform'] = 'ios';
        }
        if ($user['app_type'] == 'android') {
            $pushData['platform'] = 'android';
        }
        $res = null;
        switch ($user['push_type']) {
            case 'jpush':
                //协程发送请求
                $jpushService = $this->jpushService;
                go(function() use ($jpushService,$pushData,$user)
                {
                    $jpushService->sPush($pushData, $user['reg_id']);
                });
                $res = true;
                break;
           /*  case 'huawei':
                //协程发送请求
                $huaweiService = $this->huaweiService;
                go(function() use ($huaweiService,$pushData,$user)
                {
                    $huaweiService->sPush($pushData, $user['reg_id']);
                });
                $res = true;
                break; */
            // case 'mi':
            //     $xiaomiService = $this->xiaomiService;
            //     go(function() use ($xiaomiService,$pushData,$user)
            //     {
            //         $xiaomiService->sPush($pushData, $user['reg_id']);
            //     });
            //     $res = true;
            //     break;
            // case 'vivo':
            //     $vivosService = $this->vivosService;
            //     go(function() use ($vivosService,$pushData,$user)
            //     {
            //         $vivosService->sPush($pushData, $user['reg_id']);
            //     });
            //     $res = true;
            //     break; 
            // case 'oppo':
            //     $opposService = $this->opposService;
            //     go(function() use ($opposService,$pushData,$user)
            //     {
            //         $opposService->sPush($pushData, $user['reg_id']);
            //     });
            //     $res = true;
            //     break;            
            default:
                $res = null;
        }
        return true;
    }

}